package com.rightsidetech.http.controller.admin.system;

import com.github.pagehelper.PageInfo;
import com.rightsidetech.commom.base.PageRequest;
import com.rightsidetech.commom.base.ResponseData;
import com.rightsidetech.commom.enums.CodeIdEnum;
import com.rightsidetech.commom.utils.BeanValidator;
import com.rightsidetech.http.aspect.Auth;
import com.rightsidetech.http.aspect.Log;
import com.rightsidetech.http.aspect.ModifyLog;
import com.rightsidetech.http.aspect.Token;
import com.rightsidetech.system.dtos.request.SysRoleReq;
import com.rightsidetech.system.dtos.request.SystemParamReq;
import com.rightsidetech.system.dtos.response.SysRoleResp;
import com.rightsidetech.system.dtos.response.SystemParamResp;
import com.rightsidetech.system.service.SystemParamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.ConstraintViolation;

/**
 * @Author: yhr
 * @Date: 2021-11-10 15:05
 */
@RestController
@RequestMapping("/admin/system_param")
@ShenyuSpringMvcClient(path = "/admin/system_param/**")
@Api(tags = "admin:系统参数配置")
public class SystemParamController {
    @Resource
    private SystemParamService systemParamService;

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @GetMapping("/page")
    @ApiOperation("参数列表")
    public ResponseData<PageInfo<SystemParamResp>> page(PageRequest page) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(page);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        return systemParamService.paramPage(page);
    }

    @Log
    @Token
    @Auth(bizType = Auth.OPERATOR)
    @PostMapping("/update")
    @ApiOperation("参数修改")
    @ModifyLog(serviceClass = SystemParamService.class)
    public ResponseData update(@RequestBody SystemParamReq req) throws Exception {
        ConstraintViolation validate = BeanValidator.validate(req);
        if (validate != null) {
            return new ResponseData(CodeIdEnum.ParameterMalformed.getValue(), validate.getMessage());
        }
        return systemParamService.updateData(req);
    }
}
